package com.weiqiao.api.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.google.gson.Gson;
import com.mongodb.client.model.Filters;
import com.weiqiao.api.domain.dto.LabelShelfApiEntityDTO;
import com.weiqiao.api.repository.ILabelShelfApiRepository;
import com.weiqiao.api.service.ILabelShelfApiService;
import org.bson.conversions.Bson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ChenYF
 * @Description
 * @Date 2020/7/27 16:30
 */
@Service("IabelShelfApiServiceImpl")
public class LabelShelfApiServiceImpl implements ILabelShelfApiService {
    @Autowired
    private ILabelShelfApiRepository labelShelfApiRepository;

    @Override
    public List<LabelShelfApiEntityDTO> commodityLabelList(String company_id) {
        int companyId = Integer.parseInt(company_id);
        Bson filter = Filters.eq("delete_flag", 0);
        List<String> list = labelShelfApiRepository.getLabelShelfList(companyId, filter);
        List<LabelShelfApiEntityDTO> entityList = new ArrayList<>();
        if(CollectionUtil.isNotEmpty(list)){
            list.forEach(s -> entityList.add(new Gson().fromJson(s, LabelShelfApiEntityDTO.class)));
        }
        return entityList;
    }
}
